Unlimited Array.prototype.flat depth#55686
Unlimited Array.prototype.flat depth#55686PKrasinski wants to merge 4 commits intomicrosoft:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
|
Introducing new global types with generic names and increasing the complexity of the types enormously for a highly questionable use case. :-/ |
|
@MartinJohns Yep, probably you are right. I was just looking for the way how to type safe recurrent functions so I checked how it looks like in flat method declaration and I was a bit surprised that solution is using hard-coded array and returns wrong type when the depth is higher. So I decided to write my own implementation just for fun 😄 I could avoid new global types in this solution. I also know that probably I solved the problem that nobody had. |
|
I think for reasons discussed here and elsewhere, I would encourage people who need this to include their own local augmentations to the global scope. |
Fixes #55685
The old
Array.prototype.flatdefinition supportsdepthonly up to 21. Over 21 return wrong type.This solution allow call flat method with unlimited depth parameter.
Performance (checked with this code) is the same or better in some cases.
The only limitation of this solution is that for arrays deeper then
999levelsunknown[]type is returned.